<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
	<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
	<title>Objeto de Aprendizagem</title>
	<link href='css/style-main.css' rel='stylesheet' type='text/css' />
	<link rel='stylesheet' href='js/treeview/jquery.treeview.css' />
	<script type='text/javascript' src='js/jquery/jquery-1.7.2.min.js'> </script>
	<script type='text/javascript' src='js/treeview/jquery.treeview.js' ></script>
</head>
<body>
<?php
	require 'classes/Content.php';
	require 'classes/SimpleImage.php';
	require 'classes/SimpleText.php';
	require 'classes/Contribution.php';
	require 'classes/Credits.php';
	require 'classes/Menu.php';
	require 'classes/Link.php';
	require 'classes/MainLink.php';
	require 'classes/Page.php';
	require 'classes/LearningObject.php';
	require 'classes/ParseXML.php';

	$file = $_GET['name'];

	$parser = ParseXML::getInstance( $file );
	$object = $parser->getObject();

	$body = "<div id='tudo'>";
	echo $body;

	// Cria o header do objeto.
	$headerInfo = $object->getHeader();
	$header = "<div id='topo'  style='background:url(images/" . $file . "/" . $headerInfo->getPath() . ") 0 0 repeat-x;' >";
	$header .= "<h1 class='topo'>" . $object->getName() . "</h1></div>";
	echo $header;

	echo "<div id='conteudo'>
			<div id='menu'>";
						
	// Cria o menu dinâmicamente conforme o xml.
	$links = $object->getMenu()->getLinks();
	$menu = "<ul id='menuList'>";
	
	foreach( $links as $l )
	{
		$menu .= "<li>";
		$pageLink = "index.php?name=$file&id=" . $l->getIdLinkPage();
		$menu .= "<a href='$pageLink' >" . $l->getText() . "</a>";
		
		$subMenu = "<ul>";
		$subLinks = $l->getSubLinks();
		foreach( $subLinks as $sl )
		{
			$subMenu .= "<li>";
			$pageSubLink = "index.php?name=$file&id=" . $sl->getIdLinkPage();
			$subMenu .= "<a href='$pageSubLink' >" . $sl->getText() . "</a>";
			$subMenu .= "</li>";
		}
		$subMenu .= "</ul>";
		
		// Somente imprime o submenu caso ele possua sublinks.
		if( count( $subLinks ) > 0 )
			$menu .= $subMenu;
		
		$menu .= "</li>";
	}
	
	$menu .= "</ul>";
	echo $menu;		

	echo "	  	   </div>
				   <div id='principal'>";
	
	// Insere o conteúdo da´página.
	include 'mainContent.php';
	
	echo "			<script type='text/javascript'>
						$('#menuList').treeview({
							collapsed: true,
							animated: 'medium',
							persist: 'location'
							});
					</script>
					</div>
					<div class='clear'></div>";

	// Cria o footer do objeto.
	$footerInfo = $object->getFooter();
	$footer = "<div id='rodape' style='background:url(images/" . $file . "/" . $footerInfo->getPath() . ") center right no-repeat #FFF;'></div>";
	echo $footer;
						
	echo "		</div>";
?>
</body>
</html>
